package com.kingsystem.kingteachermarks_backend;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.sql.Types;
import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
//        String outputPath = "H:\\KingTeacherMarks_backend\\src\\main\\java";
        String outputPath = "z:\\";
        String PackageName = "com.kingsystem.kingteachermarks_backend";
//        String TableName = "Dept,calc_duration,dict_flow_status,dict_quantify,role,role_function,system_user,user_role,work_performance,work_performance_allocation,system_function";
        String TableName = "view_work_performance_allocation";

        FastAutoGenerator.create("jdbc:sqlserver://116.62.233.186:1433;databaseName=Work_Quantify;trustServerCertificate=true"
                        , "sa",
                        "KingSystem2003")
                .globalConfig(builder -> {
                    builder.author("leiyue_yao") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(outputPath);//
                })
                .dataSourceConfig(builder ->
                        builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                            int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                            if (typeCode == Types.SMALLINT) {
                                // 自定义类型转换
                                return DbColumnType.INTEGER;
                            }
                            return typeRegistry.getColumnType(metaInfo);
                        })
                )
                .packageConfig(builder ->
                        builder.parent(PackageName) // 设置父包名
//                                .moduleName("system") // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, outputPath)) // 设置mapperXml生成路径
                )
                .strategyConfig(builder ->
                        builder.addInclude(TableName) // 设置需要生成的表名
//                                .addTablePrefix("t_", "c_") // 设置过滤表前缀
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
